package org.erp.store.router;

import org.erp.common.enums.DeviceInventoryEvent;
import org.erp.store.strategy.InventoryEventStrategy;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.EnumMap;
import java.util.List;
/**
 * 库存事件路由
 */
@Component
public class InventoryEventRouter {

    @Resource
    private List<InventoryEventStrategy> inventoryEventStrategies;

    private EnumMap<DeviceInventoryEvent, InventoryEventStrategy> strategyMap;

    @PostConstruct
    public void init() {
        EnumMap<DeviceInventoryEvent, InventoryEventStrategy> map = new EnumMap<>(DeviceInventoryEvent.class);
        if (inventoryEventStrategies != null) {
            for (InventoryEventStrategy s : inventoryEventStrategies) {
                map.put(s.getEvent(), s);
            }
        }
        strategyMap = map;
    }

    public InventoryEventStrategy get(DeviceInventoryEvent event) {
        return strategyMap.get(event);
    }
}

